﻿
Imports elpmis

Namespace internalFunctions
    Public Class threadstatic_register
        Inherits internalFunction

        Public Class parameters
            Public Const name As String = "name"
            Public Const value As String = "value"
        End Class

        Public Sub New()
            MyBase.New("threadstatic.register", m_name_value)
            assert(strsame(m_name_value(0), parameters.name))
            assert(strsame(m_name_value(1), parameters.value))
        End Sub

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            Dim name As String = Nothing
            If Not ctx.findVariableStr(parameters.name, name) Then
                raiseError(errorHandle.errorType.user, "expect parameter ", parameters.name)
                Return False
            End If
            Dim value As bare_variable = Nothing
            If Not ctx.findVariable(parameters.value, value) Then
                raiseError(errorHandle.errorType.user, "expect parameter ", parameters.value)
                Return False
            End If

            output = New bare_variable(typeDefination.bool, _
                                       context.insertThreadStaticVariable(name, value) <> _
                                           context.threadStaticVariables_end())
            Return True
        End Function
    End Class
End Namespace
